let init = () => 1
let step2 = (val) => val + 2
let step3 = (val) => val + 3
let step4 = (val) => val + 4
// const steps = [step4, step3, step2, init]

const compose = function(...funcs) {
	let length = funcs.length
	let count = length - 1
	let result
	return function f1(i) {
		result = funcs[count](i)
		console.log(result, count);
		if (count <= 0) {
			count = length - 1
			return result
		}
		count--
		// console.log(result);
		return f1(result)
	}
}
compose(step4, step3, step2, init)()
